In [1]:
import numpy as np
import math
from datetime import datetime
%load_ext Cython
This number of was found in 2016 using the Great Internet Mersenne Prime Search (GIMPS). This prime is one of the Mersenne Prime whice are of the defined by the following formula:
$$2^p-1$$Where $p$ is a prime number. This is called a psudo-prime meaning not all Mersenne Prime are primes.
$2^2-1=3$
$2^3-1=7$
$2^5-1=31$
$2^7-1=127$ ...
In [2]:
2**2-1
Out[2]:
In [3]:
2**3-1
Out[3]:
In [4]:
2**5-1
Out[4]:
In [5]:
2**7-1
Out[5]:
The smallest none-prime (composite) number is $2^{11}-1=2047$ which is a composite number.
In [7]:
2**11-1
Out[7]:
The largest prime number is that was found lately is: $$2^{74,207,281}-1$$
The reason why I didn't put the actual value is that the number if very large (over 22 million digits).
In [9]:
p = 74207281
the_number = (2 ** p) - 1
In [10]:
S = 4
print(S)
print(len(str(S)))
In [11]:
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
In [12]:
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
In [13]:
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
In [14]:
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
In [15]:
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
In [16]:
# The largest prime (so far)
the_number = 2 ** 74207281 - 1
print(int(math.log10(the_number))+1, "digits")
The test is if the Mersenne Prime number of $n^2-1$ is a divided by $S_{n-2}$ you should get a remaining of 0. The problem is this series goes very large very fast. So there is another way to do this test.
In [20]:
p = 74207281
the_number = (2 ** p) - 1
S = 4
time_stamp = datetime.now()
for i in range(p-2):
S = (S ** 2 - 2) % the_number
if i % 1 == 0:
print(i, datetime.now() - time_stamp,"")
time_stamp = datetime.now()
if S == 0:
print("PRIME")
In [21]:
%%cython
cdef unsigned long p = 61
cdef unsigned long P = (2 ** p) - 1
S = 4
for i in range(p-2):
S = S ** 2 - 2
S = S % P
if i % 10 == 0:
print(i)
if S == 0:
print("PRIME")
In [ ]:
%%cython --link-args=-lgmp
cdef extern from "gmp.h":
ctypedef struct mpz_t:
pass
ctypedef unsigned long mp_bitcnt_t
cdef void mpz_init(mpz_t)
cdef void mpz_init_set_ui(mpz_t, unsigned int)
cdef void mpz_add(mpz_t, mpz_t, mpz_t)
cdef void mpz_add_ui(mpz_t, const mpz_t, unsigned long int)
cdef void mpz_sub (mpz_t, const mpz_t, const mpz_t)
cdef void mpz_sub_ui (mpz_t, const mpz_t, unsigned long int)
cdef void mpz_ui_sub (mpz_t, unsigned long int, const mpz_t)
cdef void mpz_mul (mpz_t, const mpz_t, const mpz_t)
cdef void mpz_mul_si (mpz_t, const mpz_t, long int)
cdef void mpz_mul_ui (mpz_t, const mpz_t, unsigned long int)
cdef void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t)
cdef void mpz_mod (mpz_t, const mpz_t, const mpz_t)
cdef unsigned long int mpz_get_ui(const mpz_t)
#cdef unsigned long p = 61
cdef mp_bitcnt_t p = 74207281
cdef mpz_t t # = 1
cdef mpz_t a # = 1
cdef mpz_t P # = (2 ** p) - 1
cdef mpz_t S # = 4
mpz_init(t)
mpz_init_set_ui(t, 1)
mpz_init(a)
mpz_init_set_ui(a, 2)
mpz_init(P)
mpz_mul_2exp(P,t,p)
mpz_sub_ui(P,P,1)
mpz_init(S)
mpz_init_set_ui(S, 4)
for i in range(p-2):
#S = S ** 2 - 2
mpz_mul(S,S,S)
mpz_sub_ui(S,S,2)
#S = S % P
mpz_mod(S,S,P)
if i % 1000 == 0:
print(i)
if mpz_get_ui(S) == 0:
print("PRIME")
else:
print("COMPOSITE")
#print(mpz_get_ui(P))
In [ ]: